import React, { memo } from 'react'
import {useSelector } from "react-redux";
import { Redirect } from 'react-router-dom';
import { Layout} from 'antd';
import { renderRoutes } from 'react-router-config';



import HjHeader from "../../components/header";
import HjLeftNav from "../../components/left-nav";
import Footer from "../../components/footer";
import { AdminWrapper } from "./style";


const {  Sider, Content } = Layout;



export default memo(function HjAdmin(props) {
  // redux hook
  const {isLogin} = useSelector(state => ({
     user: state.userInfo.user,
     isLogin:state.userInfo.isLogin
    }))

  // const clickqw = async ()=>{
  //      const res = await reqCategoryList()
  //    console.log(res);
  // }
   

  if(isLogin){
      return (
        <AdminWrapper>
            <Layout className="layout">
              <Sider className="sider">
                  <HjLeftNav/>
              </Sider>
              <Layout>
                <HjHeader/>
                <Content className="content">
                  {renderRoutes(props.route.routes)}
                  {renderRoutes(props.route.routes[2].routes)}
                </Content>
                <Footer/>
              </Layout>
             </Layout>
        </AdminWrapper>
      )
  }else{
    return <Redirect to="/login"/>
  }
  
})
